package com.cat.binaryTree;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/pseudo-palindromic-paths-in-a-binary-tree/
 * @create 2025/9/10 10:28
 * @since JDK17
 */

public class Solution10 {
    static int[] h = new int[10];

    public int pseudoPalindromicPaths (TreeNode root) {
        if (root == null) {
            return 0;
        }
        h[root.val]++;
        if (root.left == null && root.right == null) {  // 叶子结点
            int cnt = 0;
            for (int i = 1; i < 10; i++) {
                cnt += h[i] % 2;
            }
            h[root.val]--;
            return cnt <= 1 ? 1 : 0;
        }
        int ans = 0;
        ans += pseudoPalindromicPaths(root.left);
        ans += pseudoPalindromicPaths(root.right);
        h[root.val]--;
        return ans;
    }
}
